/** 
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 * 
 *BaseFlowFileInsController
 * 流程文件实例
 * 
 * 修改纪录
 * 2021-01-14 版本：1.0 lishuming 创建。
 * @version 版本：1.0
 * @author 作者：lishuming
 * 创建日期：2021-01-14
 */

package com.topscomm.base.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.base.controller.auto.BaseFlowFileInsControllerAuto;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: lishuming
 * @date: 2021-01-14
 * @description:流程文件实例Controller
 * @modify:
 */
@RestController
@RequestMapping("base/flowFileIns")
public class BaseFlowFileInsController extends BaseFlowFileInsControllerAuto implements IBaseFlowFileInsController {
	/**
	 * @author: lishuming
	 * @date: 2021-01-14
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		if (paraMap.containsKey("flow_id")) {
			String value = paraMap.get("flow_id").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and flowid = '{0}' ", value);
		}
		if (paraMap.containsKey("node_id")) {
			String value = paraMap.get("node_id").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and nodeid = '{0}' ", value);
		}
		if (paraMap.containsKey("flow_inst_id")) {
			String value = paraMap.get("flow_inst_id").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and flowinsid = '{0}' ", value);
		}
		if (paraMap.containsKey("node_inst_id")) {
			String value = paraMap.get("node_inst_id").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and nodeinsid = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: lishuming
	 * @date: 2021-01-14
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * 
	 * @description:批量保存
	 * @auther: wanghanwei
	 * @date: 2021年1月12日下午2:25:21
	 * @modify:
	 */
	@PostMapping(value = "/batchSave")
	public ResponseResult<Object> batchSave(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			return this.service.saveBatch(paraMap);
		} catch (Exception e) {
			return handleControllerException(e);
		}
	}

	/**
	 * 
	 * @description:
	 * @auther: wanghanwei
	 * @date: 2021年1月26日下午2:49:13
	 * @modify:
	 */
	@GetMapping(value = "/count")
	public ResponseResult<Object> count(@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			paraMap = BaseUtil.decodeSecureMap(paraMap);
			String sqlWhere = spellListSql(paraMap);
			int count = this.service.getCount(sqlWhere);
			return ResponseResult.ok(count);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}
}

